#pragma once

#include "file_system/file_reader/file_reader.h"

namespace hawking {
namespace indexlib {

class BlockFileReader : public FileReader {
public:
    static BlockCacheOption default_blk_opt;
    static AioOption default_aio_opt;

    BlockFileReader(const std::string& filepath) :
        BlockFileReader(filepath, default_blk_opt, default_aio_opt) {}
    BlockFileReader(
        const std::string& filepath,
        const BlockCacheOption& blk_opt,
        const AioOption& aio_opt);
    virtual ~BlockFileReader() = default;

    Status Init() override;
    Status Close() override {
        return Status::OK;
    }

    ReturnValue<size_t> Read(
        uint8_t* buffer, size_t length, size_t offset) override;
    ReturnValue<size_t> BatchRead(const std::vector<FilePart>& batch) override;

    size_t Length() const override {
        return accessor_->FileLength();
    }

    FSFileType FileType() const override {
        return FSFileType::FSFT_BLOCK;
    }

private:
    BlockCacheOption blk_opt_;
    AioOption aio_opt_;
    std::unique_ptr<BlockFileAccessor> accessor_;
};

}
}
